import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 账单
class HttpBillService {
  /// 账单列表
  static Future<Response> billList(int page,
      {String status, int issue_to, String keyword}) {
    return BaseConfig.httpBase.get('/api/bills', {
      'page': page,
      'status': status,
      'issue_to': issue_to,
      'keyword': keyword,
    });
  }

  /// 创建账单
  static Future<Response> createBill({
    int purchase_order_id,
    int contact_id,
    int category_id,
    String number,
    String purchase_order_number,
    String issued_at,
    String due_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    String discount_type,
    double discount_amount,
    double credit_used,
    double total,
    String notes,
    List item,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/bills', {
      "purchase_order_id": purchase_order_id,
      "contact_id": contact_id,
      "category_id": category_id,
      "number": number,
      "purchase_order_number": purchase_order_number,
      "issued_at": issued_at,
      "due_at": due_at,
      "currency_code": currency_code,
      "subtotal": subtotal,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "discount_type": discount_type,
      "discount_amount": discount_amount,
      "credit_used": credit_used,
      "total": total,
      "notes": notes,
      "items": item,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  /// 显示账单
  static Future<Response> showBill(int bill) {
    return BaseConfig.httpBase.get('/api/bills/$bill', {});
  }

  /// 更新账单
  static Future<Response> updateBill(
    int bill, {
    int purchase_order_id,
    int contact_id,
    int category_id,
    String number,
    String purchase_order_number,
    String issued_at,
    String due_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    String discount_type,
    double discount_amount,
    double credit_used,
    double total,
    String notes,
    List item,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.putJson('/api/bills/$bill', {
      "purchase_order_id": purchase_order_id,
      "contact_id": contact_id,
      "category_id": category_id,
      "number": number,
      "purchase_order_number": purchase_order_number,
      "issued_at": issued_at,
      "due_at": due_at,
      "currency_code": currency_code,
      "subtotal": subtotal,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "discount_type": discount_type,
      "discount_amount": discount_amount,
      "credit_used": credit_used,
      "total": total,
      "notes": notes,
      "items": item,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  /// 删除账单
  static Future<Response> deleteBill(int bill) {
    return BaseConfig.httpBase.deleteJson('/api/bills/$bill', {});
  }

  ///查看bill的账单
  static Future<Response> billPayment(int bill) {
    return BaseConfig.httpBase.get('/api/bills/$bill/payments', {});
  }

  /// 采购进行配送
  static Future<Response> deliver(int id) {
    return BaseConfig.httpBase.postJson('/api/bills/$id/deliver', {});
  }
}
